package com.mshop.util;


import com.mshop.fw.modules.SM;
import com.mshop.fw.util.StringUtil;
import com.mshop.po.Manager;
import com.mshop.service.ManagerService;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Sep 18, 2008 4:25:58 PM
 * @version $Id: ManagerUtil.java,v 1.2 2010/04/09 03:27:16 airsou Exp $
 */
public class ManagerUtil {
	private static final String COOKIE_NAME_USERID = "userId";
	private static final ManagerService managerService=SM.ManagerService;
	
	/**
	 * ͨ��cookie�õ��û�
	 * @param context
	 * @return
	 */
	public static Manager getMemberByCookie(WebContext context){
		String mId=context.getClientValue(COOKIE_NAME_USERID);
		Manager mb=null;
		if(!StringUtil.isEmpty(mId)&&Long.parseLong(mId)>0){
			mb=(Manager) managerService.load(mId); 
		}
		return mb;
	}
	
	public static boolean isLogin(WebContext context){
		return context.getClientValue(COOKIE_NAME_USERID)!=null;
	}
	
	/**
	 * ��¼
	 * @param context
	 * @param member
	 */
	public static void setLogin(WebContext context,Manager mb){
		if(mb!=null){
			context.setClientValue(COOKIE_NAME_USERID,mb.getId().toString());
		}
	}
	
	/**
	 * �˳���¼
	 * @param context
	 */
	public static void outLogin(WebContext context){
		context.setClientValue(COOKIE_NAME_USERID,null);
	}
}